<template>
  <div class="home">
    <div class="title">
      ♦推荐歌单♦
      <template>
        <van-icon name="replay" class="replay" size="20px" @click="replay" />
      </template>
    </div>
    <div class="cao">
      <van-row gutter="20">
        <van-col span="8" v-for="item in repRecommend" :key="item.id">
          <van-image
            width="100%"
            height="110px"
            fit="contain"
            radius="10"
            :src="item.picUrl"
          />
          <p class="song_name">{{ item.name }}</p>
        </van-col>
      </van-row>
    </div>
    <!-- <div class="title" style="margin-top:15px">
      ♦最新音乐♦
    </div> -->
    <van-divider
      content-position="left"
      hairline
      class="New"
      :style="{
        color: '#b9ac9c',
        borderColor: '#58a183',
        padding: '30px 16px 0'
      }"
      >最新音乐</van-divider
    >
    <van-cell
      :title="item.name"
      :label="item.song.artists[0].name + ' - ' + item.name"
      center
      v-for="item in musicList"
      :key="item.id"
      @click="$router.push({ name: 'play', query: { id: item.id } })"
    >
      <!-- 使用 right-icon 插槽来自定义右侧图标 -->
      <template #right-icon>
        <van-icon name="play-circle-o" size="20" />
      </template>
    </van-cell>
  </div>
</template>

<script>
import { recommendListAPI, newMusicListAPI } from '@/api'
export default {
  data () {
    return {
      recommend: [],
      repRecommend: [],
      index: 0,

      musicList: []
    }
  },
  async created () {
    // 推荐歌单
    let res = await recommendListAPI({
      limit: 30
    })
    this.recommend = res.data.result
    while (true) {
      let a = this.recommend[this.index]
      this.repRecommend.push(a)
      this.index++
      if (this.repRecommend.length == 6) {
        break
      }
    }
    // 最新页面
    newMusicListAPI().then(res => {
      this.musicList = res.data.result
    })
  },
  methods: {
    replay () {
      this.repRecommend = []
      while (true) {
        let a = this.recommend[this.index]
        this.repRecommend.push(a)
        this.index++
        if (this.repRecommend.length == 6) {
          if (this.index == 30) {
            this.index = 0
          }
          break
        }
      }
    }
  }
}
</script>

<style>
.home {
  /* padding-top: 46px; */
  /* padding-bottom: 50px; */
  background-size: initial;
  background: url('../../assets/动次打次4.gif') no-repeat;
}
/* 标题 */
.title {
  padding: 0.266667rem 0.24rem;
  margin: 0 0 0.24rem 0;
  background-color: #eee;
  color: #333;
  font-size: 15px;
  margin-top: -50px;
}
/* 推荐歌单 - 歌名 */
.song_name {
  font-size: 0.346667rem;
  padding: 0 0.08rem;
  margin-bottom: 0.266667rem;
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
  -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  -webkit-line-clamp: 2; /** 显示的行数 **/
  overflow: hidden; /** 隐藏超出的内容 **/
}
.New {
  margin-top: 0px;
}
.replay {
  position: absolute;
  right: 0;
  margin-right: 10px;
  margin-top: 2px;
}
.van-row {
  height: 100px !important;
}
</style>
